'''
行业分析
'''

from flask import jsonify, request

from db.dao import StockPoolDao
from utils.util import FlaskTool
from web import custom


@custom.route('/pool/query-all')
def stock_pool():
    pagination = StockPoolDao().queryByPage(request.args)
    return jsonify(FlaskTool.paginatioToList(pagination))


@custom.route('/pool/industry', methods=['GET', 'POST'])
def stock_pool_industry():
    '''
    股票池里的行业集合
    '''
    industry_list = StockPoolDao().queryPoolIndustry()
    keys = ('industry_code', 'industry_name')
    return jsonify([dict(zip(keys, values)) for values in industry_list])


@custom.route('/pool/remove-pool-batch')
def remove_stock_pool():
    args_get = request.args.get('ids')
    if not args_get:
        return 'ok'
    split = args_get.split(',')
    ids = [int(idstr) for idstr in split]
    StockPoolDao().removeStockPoolBatch(ids)

    return 'ok'

